package com.awei.study.annotation.customize;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Aspect
@Component
public class TestAspect {

    @Pointcut("@annotation(com.awei.study.annotation.customize.Test)")
    public void testPointCut() {

    }

    @AfterReturning(pointcut = "testPointCut()",returning = "result")
    public void print(JoinPoint joinPoint,Object result) {
        Signature signature = joinPoint.getSignature();
        MethodSignature methodSignature = (MethodSignature) signature;
        Method method = methodSignature.getMethod();
        Test test = method.getAnnotation(Test.class);
        System.out.println(test.value());
        System.out.println(result);
    }

}
